<?php

define("FILES", "files/");
define("SRC", "../src");

/**
* Illiad PHP framework loader
*/
function loadSource($dir, $recursive)
{
    if (is_dir($dir))
    {
        $dirHandle = opendir($dir);
        if ($dirHandle)
        {
            $file = readdir($dirHandle);
            while ($file !== false)
            {
                if ((strlen($dir) > 1) && (substr($dir, -1) !== '/')) $dir .= '/';
                $filename = $dir . $file;
                
                if (is_file($filename) && (strlen($file) > 4) && (substr($file, -4) == '.php') && ($file !== 'iliadloader.php'))
                    include $filename;
                else if ($recursive && is_dir($filename) && ($file !== '.') && ($file !== '..'))
                    loadSource($filename, true);
                
                $file = readdir($dirHandle);
            }
            closedir($dirHandle);
        }
    }
}

// Load all illiad framework files
$pathInfo = pathinfo(__FILE__);
loadSource($pathInfo['dirname'], true);

// Load application's sources
loadSource(getcwd() . '/' . SRC, true);

?>